//
//  replay_detial_VC.m
//  LoveLove
//
//  Created by 吴志强 on 2019/6/26.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "replay_detial_VC.h"
#import "subCommentCell.h"
#import "QZTopTextView.h"

@interface replay_detial_VC ()<QZTopTextViewDelegate>
/**
 评论框
 */
@property (nonatomic,strong) QZTopTextView *commentTextView;

@property (nonatomic,strong) NSDictionary *returnDic;
@end

@implementation replay_detial_VC
-(QZTopTextView *)commentTextView{
    if (!_commentTextView) {
        _commentTextView = [QZTopTextView new];
        _commentTextView.isNavi = YES;
        _commentTextView.delegate = self;
    }
    return _commentTextView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
     [self.view addSubview:self.commentTextView];//评论框
}

/**
 发表评论

 @param comment 内容
 */
//-(void)commitComment:(NSString *)comment
//{
//    LLUserInfo *user = [LLUserInfo sharedUser];
//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//    [dic setObject:@"22" forKey:@"edu_id"];
//    [dic setObject:user.user_id forKey:@"user_id"];
//    [dic setObject:user.user_random forKey:@"user_random"];
//    [dic setObject:comment forKey:@"comment"];
//    [dic setObject:self.newsId forKey:@"new_id"];
//    [self showSVProgressHUD];
//
//    [LLHttpTool post:LLHOST headParams:nil params:dic success:^(NSDictionary *result) {
//            //        [SVProgressHUD dismiss];
//        if([result[@"code"] integerValue] == 0){
//            [self showSVProgressHUDInfoWithsStatus:@"发表成功"];
//        }else
//            [self showSVProgressHUDInfoWithsStatus:result[@"msg"]];
//
//
//
//    } failure:^(NSString *msg) {
//        [SVProgressHUD showErrorWithStatus:msg];
//    }];
//}


#pragma mark----tableviewdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.data_array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *string = @"videocell";
    subCommentCell *cell = [[subCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];
    cell.data = self.data_array[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    self.returnDic = self.data_array[indexPath.row];
     [self.commentTextView.countNumTextView becomeFirstResponder];
}
#pragma mark---QZTopTextViewDelegate


- (void)sendComment:(NSString *)comment{
    
    NSString *commentStr = self.commentTextView.countNumTextView.text;
    if (commentStr.length == 0) {
        [self showSVProgressHUDInfoWithsStatus:@"请输入内容"];
        return;
    }
    [self commitComment:commentStr];
}

/**
 发表评论
 
 @param comment 内容
 */
-(void)commitComment:(NSString *)comment{
    //edu_id:22(固定值)
    //user_id: 用户的id
    //user_random: 随机数
    //comment: 评论内容
    
//    {
//        comment = "\U6211\U62a5\U8fd9\U4e48\U4e45\U4e86\U8def\U8fc7";
//        time = "2019-06-26 22:20:33";
//        "u_avatar" = "http://www.haoaih.com/uploads/users/users.jpg";
//        "u_id" = 4;
//        "u_name" = "\U4f60\U597d";
//        uavatar = "http://www.haoaih.com/uploads/users/users.jpg";
//        uid = 4;
//        uname = "\U4f60\U597d";
//    }
    LLUserInfo *user = [LLUserInfo sharedUser];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary: @{@"edu_id":@"22"}];
    [dic setObject:user.user_id forKey:@"user_id"];
    [dic setObject:user.user_random forKey:@"user_random"];
    [dic setObject:comment forKey:@"comment"];
    [dic setObject:self.newsId forKey:@"new_id"];
    
        [dic setObject:self.commentId forKey:@"c_id"];
        [dic setObject:self.returnDic[@"uid"] forKey:@"uid"];
    
    [self showSVProgressHUD];
    [LLHttpTool post:LLHOST headParams:nil params:dic success:^(NSDictionary *result) {
                [SVProgressHUD dismiss];
        
        if([result[@"code"] integerValue] == 0){
            [SVProgressHUD showSVProgressHUDInfoWithsStatus:@"回复成功"];
            if (self.commentBlock) {
                self.commentBlock();
            }
            [self.navigationController popViewControllerAnimated:YES];
            
        }else
            [SVProgressHUD showSVProgressHUDInfoWithsStatus:result[@"msg"]];
        
        
        
    } failure:^(NSString *msg) {
        [SVProgressHUD showErrorWithStatus:msg];
    }];
}

@end
